﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ctrlUse
{
    public partial class Form1 : Form
    {
        BindingSource source = new BindingSource();
        BindingSource source1 = new BindingSource();
        BindingSource source2 = new BindingSource();

        public Form1()
        {
            InitializeComponent();
            dataGridView1.DataSource = bindingSource1;
            comboBox1.DataSource = source;
            listBox1.DataSource = source2;

            // 从资源文件中获取图片
            Bitmap bm = Properties.Resources._06_1528519461798;
            pictureBox1.Image = bm;
            //pictureBox1.Image = new Bitmap("E:\\图片\\39\\03_1528519459694.jpg");
            //pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;// 图片多大就多大
            pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; // 缩放模式
        }

        

        private void button1_Click(object sender, EventArgs e)
        {
            // 获取选中的选项，这里返回的就是选中的项，可以转换成字符串，或其他类型
            object sItem = comboBox1.SelectedItem;
            object v = comboBox1.Items[comboBox1.SelectedIndex];
            string value = Convert.ToString(sItem);
            //MessageBox.Show(sItem.ToString());
            //MessageBox.Show(v.ToString());
            MessageBox.Show(value);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            source.Clear();
            bindingSource1.Clear();

            List<string> addrs = new List<string>();
            addrs.Add("北京");
            addrs.Add("上海");
            addrs.Add("广州");
            addrs.Add("深圳");

            foreach(string v in addrs)
            {
                source.Add(v);
                bindingSource1.Add(v);
            }

            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            source.Clear();
            bindingSource1.Clear();

            List<Person> persons = new List<Person>();

            persons.Add(new Person()
            {
                Name = "yejing",Addr = "guangzhou"
            });

            persons.AddRange(new Person[] {

                new Person(){
                    Name = "张三",Addr = "香港"
                },
                new Person(){
                    Name = "王五",Addr = "深圳"
                },
                new Person(){
                    Name = "马六",Addr = "北京"
                }
            });


            foreach(Person p in persons)
            {
                source.Add(p);
                bindingSource1.Add(p);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            source.Clear();

            List<Person> persons = new List<Person>();

            persons.Add(new Person()
            {
                Name = "yejing",
                Addr = "guangzhou"
            });

            persons.AddRange(new Person[] {

                new Person(){
                    Name = "张三",Addr = "香港"
                },
                new Person(){
                    Name = "王五",Addr = "深圳"
                },
                new Person(){
                    Name = "马六",Addr = "北京"
                }
            });


            foreach (Person p in persons)
            {
                source2.Add(p);
            }
        }

        private void OnListChanged(object sender, ListChangedEventArgs e)
        {
            System.Collections.IList list = bindingSource1.List;
            MessageBox.Show(list.Count+"");
        }
    }


}
